import React from 'react';
import { observer, inject } from 'mobx-react';
import css from './index.less';
import PageContentRender from 'components/pageContentRender';
import PropTypes from 'prop-types';

/**
 * 轮播内页
 */
@inject('store')
@observer
export default class SliderPage extends React.Component {

  static propTypes = {
    mod: PropTypes.object.isRequired,
  };

  render() {
    const { mod, store: { project: { currentPages } } } = this.props;
    if (!mod) {
      return (
        <div>
          页面渲染失败
        </div>
      );
    }
    const isThumb = currentPages !== mod.parent;
    const props = {
      className: css.sliderPage,
      style: mod.style,
      onMouseDown: (e) => {
        if (!isThumb) {
          e.stopPropagation();
          mod.selectSelf();
        }
      }
    };

    const pageContentProps = {
      mod,
      isThumb,
    };

    return (
      <div {...props}>
        <PageContentRender {...pageContentProps} />
      </div>
    );
  }
}
